import React from 'react';
import CommonList from 'src/components/CommonLists/list';
import { Button, message } from 'antd'
import services from '../../../services/api';
import Statistics from '../../Strategy/Strategy/statistics';
import Modal from 'src/components/Modal';

export default class extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'produce';
    this.operatorWidth = 120;
    this.trendButton = record => {
      return (
        <Button size='small' type='link' onClick={this.trend.bind(this, record)}>
          趋势图
        </Button>
      );
    };
    this.versionsButton = record => {
      return (
        <Button size='small' type='link' onClick={this.versions.bind(this, record)}>
          发布记录
        </Button>
      );
    };
    this.btnGroup = [this.trendButton, this.versionsButton]; // 默认只有编辑、删除两个button, 扩展组件重写这个变量则可覆盖
  }
  componentDidMount() {}

  offfline = (record) => {
    let params = {
      strategy_id: record.strategy_id,
      version: record.version
    }
    services.produce.offfline(params).then(res => {
      if (res.code === 0) {
        message.success(res.msg)
      } else {
        message.error(res.msg)
      }
    })
  }

  trend = (record) => {
    Modal.open({
      title: '策略趋势展示',
      width: '1000px',
      content: <Statistics event_id={record.event_id} app_id={record.app_id} api='produce' />,
      isOkBtn: true,
      isCancelBtn: true,
      ok: () => {
        Modal.close();
      },
      cancel: () => {
        Modal.close();
      },
    });
  }

  versions = (record) => {
    this.props.history.push(`/produce/produce/${record.event_id}/version`);
  }
}
